package com.us.usws.common.resourcetree.model;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractTreeNode<T extends AbstractTreeNode<?>> {

	private long id;
	private String text;
	private boolean expanded;
	private boolean leaf;
	private String iconCls;
	private String typeCode;

	private String name;

	private long parentId;

	private List<T> children;
	
	public AbstractTreeNode() {
	}

	public AbstractTreeNode(long id) {
		this.id = id;
	}

	public AbstractTreeNode(long id, String text) {
		this.id = id;
		this.text = text;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public boolean isExpanded() {
		return expanded;
	}

	public void setExpanded(boolean expanded) {
		this.expanded = expanded;
	}

	public boolean isLeaf() {
		if (getChildren().isEmpty()) {
			setLeaf(true);
		}
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public List<T> getChildren() {
		if (children == null) {
			children = new ArrayList<T>();
		}
		return children;
	}

	public void add(T node) {
		getChildren().add(node);
	}

	public void addAll(List<T> nodes) {
		getChildren().addAll(nodes);
	}

	public String getIconCls() {
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	public String getTypeCode() {
		return typeCode;
	}

	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getParentId() {
		return parentId;
	}

	public void setParentId(long parentId) {
		this.parentId = parentId;
	}

	public void setChildren(List<T> children) {
		this.children = children;
	}

}
